/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author xgzheng
 */
public class SellItem implements TableInterface {

    private int siId;
    private Sell siSell;
    private Product siProduct;
    private Color siColor;
    private double siProductNum;
    private double siSubTotal;
    private double siperprice;

    public int getSiId() {
        return siId;
    }

    public void setSiId(int siId) {
        this.siId = siId;
    }

    public Product getSiProduct() {
        return siProduct;
    }

    public void setSiProduct(Product siProduct) {
        this.siProduct = siProduct;
    }

    public double getSiProductNum() {
        return siProductNum;
    }

    public void setSiProductNum(double siProductNum) {
        this.siProductNum = siProductNum;
    }

    public Sell getSiSell() {
        return siSell;
    }

    public void setSiSell(Sell siSell) {
        this.siSell = siSell;
    }

    public double getSiSubTotal() {
        return siSubTotal;
    }

    public void setSiSubTotal(double siSubTotal) {
        this.siSubTotal = siSubTotal;
    }

    public void insert(PreparedStatement pstmt) throws SQLException {
        pstmt.setInt(1, siId);
        pstmt.setInt(2, siSell.getsId());
        pstmt.setInt(3, siProduct.getpId());
        pstmt.setDouble(4, siProductNum);
        pstmt.setDouble(5, siSubTotal);
        pstmt.setDouble(6, siperprice);
        if (siColor != null) {
            pstmt.setInt(7, siColor.getCid());
        } else {
            //如果未指定颜色，则将颜色ID复制未-1，表示未指定颜色
            pstmt.setInt(7, -1);
        }

        pstmt.executeUpdate();
        pstmt.close();
    }

    public String getTableName() {
        return "sellitem";
    }

    public int getTableColumnCount() {
        return 7;
    }

    public String getPrimaryKey() {
        return "siid";
    }

    public Object getObject(ResultSet resultSet) throws SQLException {
//        throw new UnsupportedOperationException("Not supported yet.");
        return null;
    }

    /**
     * @return the siperprice
     */
    public double getSiperprice() {
        return siperprice;
    }

    /**
     * @param siperprice the siperprice to set
     */
    public void setSiperprice(double siperprice) {
        this.siperprice = siperprice;
    }

    /**
     * @return the siColor
     */
    public Color getSiColor() {
        return siColor;
    }

    /**
     * @param siColor the siColor to set
     */
    public void setSiColor(Color siColor) {
        this.siColor = siColor;
    }
}
